#include "dialogloginpad.h"
#include "ui_dialogloginpad.h"

DialogLoginPad::DialogLoginPad(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogLoginPad)
{
    ui->setupUi(this);

#if INDOOREMBED
    setWindowFlags(Qt::FramelessWindowHint);//隐藏窗口标题栏
#endif

    //取消按键虚线框
    ui->pbn_dialpad_num0->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num1->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num2->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num3->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num4->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num5->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num6->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num7->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num8->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_num9->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_cancel->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_enter->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_asterisk->setFocusPolicy(Qt::NoFocus);
    ui->pbn_dialpad_sharp->setFocusPolicy(Qt::NoFocus);
    ui->pbn_home->setFocusPolicy(Qt::NoFocus);
    ui->pbn_back->setFocusPolicy(Qt::NoFocus);

    ui->pbn_home->setText("");
    ui->pbn_back->setText("");
    ui->pbn_dialpad_num0->setText("");
    ui->pbn_dialpad_num1->setText("");
    ui->pbn_dialpad_num2->setText("");
    ui->pbn_dialpad_num3->setText("");
    ui->pbn_dialpad_num4->setText("");
    ui->pbn_dialpad_num5->setText("");
    ui->pbn_dialpad_num6->setText("");
    ui->pbn_dialpad_num7->setText("");
    ui->pbn_dialpad_num8->setText("");
    ui->pbn_dialpad_num9->setText("");
    ui->pbn_dialpad_cancel->setText("");
    ui->pbn_dialpad_enter->setText("");
    ui->pbn_dialpad_asterisk->setText("");
    ui->pbn_dialpad_sharp->setText("");

    connect(ui->pbn_back, SIGNAL(clicked()), this, SLOT(close()));

    connect(ui->pbn_dialpad_num0, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num1, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num2, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num3, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num4, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num5, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num6, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num7, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num8, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_num9, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_asterisk, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_sharp, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_cancel, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));
    connect(ui->pbn_dialpad_enter, SIGNAL(clicked()), this, SLOT(on_pbn_dialpad_clicked()));    

    ui->edt_Password->setEchoMode(QLineEdit::Password);
}

void DialogLoginPad::on_pbn_dialpad_clicked()
{
    QPushButton*  sender= (QPushButton*)(this->sender());
    printf("on_pbn_dialpad_clicked\n");
    if(ui->pbn_dialpad_num0 == sender)
    {
        QString str= ui->edt_Password->text() + "0";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num1 == sender)
    {
        QString str= ui->edt_Password->text() + "1";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num2 == sender)
    {
        QString str= ui->edt_Password->text() + "2";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num3 == sender)
    {
        QString str= ui->edt_Password->text() + "3";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num4 == sender)
    {
        QString str= ui->edt_Password->text() + "4";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num5 == sender)
    {
        QString str= ui->edt_Password->text() + "5";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num6 == sender)
    {
        QString str= ui->edt_Password->text() + "6";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num7 == sender)
    {
        QString str= ui->edt_Password->text() + "7";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num8 == sender)
    {
        QString str= ui->edt_Password->text() + "8";
        ui->edt_Password->setText(str);
    }
    else if(ui->pbn_dialpad_num9 == sender)
    {
        QString str= ui->edt_Password->text() + "9";
        ui->edt_Password->setText(str);
    }
    else if((ui->pbn_dialpad_asterisk == sender) || (ui->pbn_dialpad_cancel == sender))
    {
        QString str= ui->edt_Password->text();
        str.remove(str.length()-1, 1);
        ui->edt_Password->setText(str);
    }

}


DialogLoginPad::~DialogLoginPad()
{
    delete ui;
}

void DialogLoginPad::paintEvent(QPaintEvent *event)
{
    //printf("DialogHomeNavigation paintEvent \n");
#if 0
    QPainter painter(this);
    painter.drawPixmap(0, 0, 800, 480, QPixmap("./images/setuplogin.jpg"));
#endif
}
